<?php
@ob_start();
@session_start();

include("../connect/connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-</title>
<link rel="stylesheet" href="stylereport.css" type="text/css" />
<link rel="shortcut icon" href="../image/Letter-T.ico" />
</head>
<?php

if($_GET['action']=='endsale') {

	$Query = mysql_query("SELECT product.prod_name,stock_bar_cut.* FROM product,stock_bar_cut,stock_bar WHERE product.prod_id = stock_bar.prod_id AND stock_bar_cut.stock_bar_id = stock_bar.stock_bar_id");
	
	while($row = mysql_fetch_array($Query)) {
		$yesterday = ($row['stock_bar_cut_yesterday']+$row['stock_bar_cut_receive'])-$row['stock_bar_cut_sale'];
		mysql_query("UPDATE stock_bar_cut SET stock_bar_cut_yesterday = '".$yesterday."' ,stock_bar_cut_receive = '0' ,stock_bar_cut_sale = '0' , stock_bar_cut_status = '1' WHERE stock_bar_cut_id = '".$row['stock_bar_cut_id']."' ");
		
		mysql_query("INSERT INTO stock_bar_store (prod_name,stock_bar_store_yesterday,stock_bar_store_receive,stock_bar_store_sale,stock_bar_store_date) VALUES ('".$row['prod_name']."','".$row['stock_bar_cut_yesterday']."','".$row['stock_bar_cut_receive']."','".$row['stock_bar_cut_sale']."','".$row['stock_bar_cut_date']."')");
	}
	
		$abc = "ปิดการขายเรียบร้อยแล้ว";
		$wait = "อีก 5 วินาทีจะกลับไปสู่หน้าแรกอีกครั้ง";
	echo "<script type=\"text/javascript\"> setTimeout(\"location.href='../sale/index.php'; \", 5000);</script>";
}
?>
<body>
<font size="6" color="red"><center><?php echo $abc; ?></center></font>
<br />
<font size="5" color="red"><center><?php echo $wait; ?></center></font>
</body>

</html>
